package cst.a000wxb.fragment115wxb.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import cst.a000wxb.fragment115wxb.R;
import cst.a000wxb.fragment115wxb.adapter.ArticleAdapter;
import cst.a000wxb.fragment115wxb.bean.ArticleBean;
import cst.a000wxb.fragment115wxb.iface.ArticleListener;
import cst.a000wxb.fragment115wxb.model.ArticleModel;


/**
 * Created by Bobx on 2017/5/26.
 */

public class WechatFragment extends Fragment {
    private View view;
    private Context context;
    // private TextView textView;
    RecyclerView recyclerView;
    RecyclerView.LayoutManager layoutManager;
    ArticleAdapter articleAdapter;
    List<ArticleBean> list = null;
    ArticleListener articleListener = new ArticleListener() {
        @Override
        public void onResponse(List<ArticleBean> alist) {
            list = alist;
            articleAdapter.setList(list);
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();

        }
    };



    @Override
    public View onCreateView(LayoutInflater inflater
            , ViewGroup container,
                             Bundle savedInstanceState) {

        context = getActivity();
        view = inflater.inflate(R.layout.wechatlaout,container,false);
        //textView = (TextView)view.findViewById(R.id.weChattextView);
        // textView.setText("MMP");
        recyclerView = (RecyclerView)view.findViewById(R.id.fuck);
        layoutManager = new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);

        articleAdapter = new ArticleAdapter(context);
        articleAdapter.setList(list);
        recyclerView.setAdapter(articleAdapter);

        ArticleModel articleModel = new ArticleModel();
        articleModel.getResultList("article",3,"2ts2j910hv4m270hipde4a67d7",articleListener);


        Toast.makeText(context,"MMP",Toast.LENGTH_SHORT).show();

        return view;
    }

}

